<?php
/**
 * CHeaderPortlet class file.
 *
 * @author Lucas Vasconcelos <contato@lucasvasconcelos.com>
 * @copyright Copyright(c) 2010 Lucas Vasconcelos
 * @license BSD License http://www.lucasvasconcelos.com/yap/license
 * @link http://www.lucasvasconcelos.com/yap/
 * @version $Id: CHeaderPortlet.php 23 2010-02-10 13:16:00Z contato@lucasvasconcelos.com $
 * @package yap.web.portlets
 */

Prado::using('yap.web.portlets.CPortlet');

/**
 * CHeaderPortlet class.
 *
 * @author Lucas Vasconcelos <contato@lucasvasconcelos.com>
 * @version 1.0 $Revision: 23 $
 * @package yap.web.portlets
 */
class CHeaderPortlet extends CPortlet
{
	public function onLoad($param)
	{
		parent::onLoad($param);
		if($this->getPage() instanceof IPageCrud)
		{
			$this->setupLinks();
			$this->displayLinks();
		}
	}

	public function setTitle($value)
	{
		$this->setViewState('Title',$value,'');
	}

	public function getTitle()
	{
		return $this->getViewState('Title','');
	}

	public function setSubTitle($value)
	{
		$this->setViewState('SubTitle',$value,'');
	}

	public function getSubTitle()
	{
		return $this->getViewState('SubTitle','');
	}

//	public function setCreateLink($value)
//	{
//		$this->setViewState('CreateLink',$value,'Normal');
//	}
//
//	public function getCreateLink()
//	{
//		return $this->getViewState('CreateLink','Normal');
//	}
//
//	public function setDeleteLink($value)
//	{
//		$this->setViewState('DeleteLink',$value,'Normal');
//	}
//
//	public function getDeleteLink()
//	{
//		return $this->getViewState('DeleteLink','Normal');
//	}

	protected function displayLinks()
	{
		//$this->lnk_create->setVisible($this->getCreateLink()!=='Invisible' && ($this->getPage()->getAction()===CActionType::View || $this->getPage()->getAction()===CActionType::Read));
		//$this->lnk_delete->setVisible($this->getDeleteLink()!=='Invisible' && ($this->getPage()->getAction()===CActionType::View || $this->getPage()->getAction()===CActionType::Update));
		if($this->getNamingContainer() instanceof CPortlet)
			$allowed=$this->getNamingContainer()->allowedActions();
		else
			$allowed=$this->getPage()->allowedActions();
		$this->lnk_create->setVisible(in_array(CActionType::Create,$allowed) && ($this->getPage()->getAction()===CActionType::View || $this->getPage()->getAction()===CActionType::Read));
		$this->lnk_delete->setVisible(in_array(CActionType::Delete,$allowed) && ($this->getPage()->getAction()===CActionType::View || $this->getPage()->getAction()===CActionType::Update));
	}

	protected function setupLinks()
	{
		$this->lnk_create->setText('Incluir');
		$this->lnk_create->setToolTip('Incluir novo registro.');
		$this->lnk_create->setCssClass('add');
		$this->lnk_create->setNavigateUrl($this->getPage()->constructUrl(CActionType::Create));
		$this->lnk_create->setVisible('false');

		$this->lnk_delete->setText('Excluir');
		$this->lnk_delete->setToolTip('Excluir o registro.');
		$this->lnk_delete->setCssClass('del');
		$this->lnk_delete->setNavigateUrl($this->getPage()->constructUrl(CActionType::Delete, $this->getPage()->getRecordId()));
		$this->lnk_delete->getAttributes()->onclick='return confirm(\'Tem certeza que deseja excluir este registro?\');';
		$this->lnk_delete->setVisible('false');

		$this->lnk_close->setText('Fechar');
		$this->lnk_close->setToolTip('Fechar esta janela.');
		$this->lnk_close->setCssClass('close');
		$this->lnk_close->setNavigateUrl('#');
		$this->lnk_close->getAttributes()->onclick='javascript:window.close()';
		$this->lnk_close->setVisible('false');
	}
}